package adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import app.Application;
import base.BasePage;
import bean.MainFunBean;
import shanshuitiancheng.news.R;

/**
 * Created by cch on 2016/6/22.
 */
public class MainAdapter1 extends BaseAdapter{
    private List<MainFunBean.NewsBean> newsdata;
    private Context ct;
    public MainAdapter1(List<MainFunBean.NewsBean> newsData, Context ct) {
        this.ct = ct;
        this.newsdata = newsData;
    }

    @Override
    public int getCount() {
        return newsdata.size();
    }

    @Override
    public Object getItem(int position) {
        return newsdata.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(ct).inflate(R.layout.functionview,null);
             holder = new ViewHolder();
            holder.image = (ImageView) convertView.findViewById(R.id.image);
            holder.title = (TextView) convertView.findViewById(R.id.tv1);
            holder.description = (TextView) convertView.findViewById(R.id.tv2);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        String title = newsdata.get(position).getTitle();
        String des = newsdata.get(position).getWriter();
        List<String> ima = newsdata.get(position).getImgs();
        if (ima != null && ima.size() > 0){
            String s = ima.get(0);
            Application.universalImageLoader.displayImage(s,holder.image,Application.options);
        }
//        else if (!TextUtils.isEmpty(litPic)){
//            Application.universalImageLoader.displayImage();
//        }
        holder.title.setText(title);
        holder.description.setText(des);
        return convertView;
    }
    class ViewHolder{
        private ImageView image;
        private TextView title,description;
    }
}
